package com.lnkj.spcj.base


import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.just.agentweb.AgentWeb

import com.lnkj.spcj.R
import kotlinx.android.synthetic.main.fragment_web_view.*


/**
 * A simple [Fragment] subclass.
 */
class WebViewFragment : Fragment() {
    var mAgentWeb: AgentWeb? = null

    companion object {
        fun newInstance(args: Bundle?): WebViewFragment {
            val fragment = WebViewFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_web_view, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        loadUrl(arguments?.getString("url") ?: "")
    }

    fun loadUrl(url: String) {
        try {
            mAgentWeb = AgentWeb.with(this)
                    .setAgentWebParent(rl_cotainer, LinearLayout.LayoutParams(-1, -1))
                    .closeIndicator()
                    .createAgentWeb()
                    .ready().go(url)
        } catch (e: Exception) {
        }
    }


}
